package bio.duplexing;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Common {

    public static void printInContent(InputStream inputStream) {
        new Thread() { //接收输入的线程
            @Override
            public void run() {
                Scanner scanner = new Scanner(inputStream);
                while (true) {
                    if (scanner.hasNextLine()) {
                        System.out.println("收到：" + scanner.nextLine());
                    }
                }
            }
        }.start();
    }

    public static void printOutContent(OutputStream outputStream) {
        new Thread() { //接收输出的线程
            @Override
            public void run() {
                Scanner scanner = new Scanner(System.in);
                PrintWriter printWriter = new PrintWriter(outputStream);
                while (scanner.hasNextLine()) {
                    printWriter.println(scanner.nextLine());
                    printWriter.flush();
                }
            }
        }.start();
    }
}
